﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace System
{
    [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
    public sealed class TagAttribute : Attribute
    {
        public TagAttribute()
        {
        }

        public TagAttribute(string tag)
            :this()
        {
            this.Tag = tag;
        }

        private string _Tag;
        public string Tag
        {
            get { return _Tag; }
            set { _Tag = value; }
        }
    }

    public static class TagExtension
    {
        public static bool IsTagged(this MemberInfo mem, string tag)
        {
            var tagA = mem.GetAttributesOfType(typeof(TagAttribute),false).Cast<TagAttribute>();
            return tagA.Any(s => s.Tag == tag);
        }

        public static bool IsTagged(this Assembly asm, string tag)
        {
            var tagA = asm.GetCustomAttributes(typeof(TagAttribute), false).Cast<TagAttribute>();
            return tagA.Any(s => s.Tag == tag);
        }
    }
}
